/**
 * The scores package of the application.
 */
package fr.umlv.m2.android.quizz.scores;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import fr.umlv.m2.android.quizz.R;
import fr.umlv.m2.android.quizz.database.Level;
import fr.umlv.m2.android.quizz.database.LevelDb;
import fr.umlv.m2.android.quizz.database.Theme;
import fr.umlv.m2.android.quizz.database.ThemeDb;

/**
 * This class defines single player scores activity according level.
 * 
 * @author Gambouele Bertrand.
 * @author Viravout Alexandre.
 */
public class ScoresSinglePlayerByLevelActivity extends TabActivity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.tab_without_icon);

		Intent intent = this.getIntent();
	    final Bundle bundle = intent.getExtras();
	    final long levelId = bundle.getLong("levelId");
		
		final TabHost tabHost = this.getTabHost();
		
		ThemeDb themeDb = new ThemeDb(this);
		final LevelDb levelDb = new LevelDb(this);
		themeDb.open();
		levelDb.open();
		
		Level level = levelDb.getLevelWithId(levelId);
		
		levelDb.close();
		
		for(Theme theme : themeDb.getThemesWithLevel(level.getId())) {
			TabSpec tab = tabHost.newTabSpec(theme.getName().toLowerCase());
		    tab.setIndicator(theme.getName());
		    
		    intent = new Intent(this, ScoresSinglePlayerByThemeActivity.class);
			this.setTitle(
					this.getResources().getString(R.string.scoresSinglePlayerBarTitle) +
					" " +
					level.getName().toLowerCase()		
			);
			intent.putExtra("levelId", levelId);
			intent.putExtra("themeId", theme.getId());
		    tab.setContent(intent);
		    
		    tabHost.addTab(tab);
		}
		
		themeDb.close();
	    
	    for(int i=0; i<tabHost.getTabWidget().getChildCount(); i++) {	    	
	    	tabHost.getTabWidget().getChildAt(i).setPadding(0, -18, 0, 18);
	    }
	}
}
